package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.afterSalesFaultPartsPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName:afterSalesFaultPartsMapp
 * Package:com.example.mapper
 * Description:
 *
 * @Author：牧星苑
 * @Create 2025/10/8 16:10
 * @Version 1.0
 */
@Mapper
public interface afterSalesFaultPartsMapp {
    //根据分页查询返件清单
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_after_sales_fault_parts where sys_deleted=0 " +
            "order by create_time DESC " +
            "limit #{startRow}, #{size}")
    List<afterSalesFaultPartsPojo> queryByPage(Integer startRow, Integer size);

    //查询所有返件清单条数
    @DS("newMscLowCodeFormal")
    @Select("SELECT COUNT(*) FROM ddm_after_sales_fault_parts where sys_deleted=0")
    Integer queryQuantity();

    //插入一行返件清单
    @DS("newMscLowCodeFormal")
    @Insert("insert into ddm_after_sales_fault_parts (" +
            "id, create_time, update_time, " +
            "creator, process_status, sys_update_user, " +
            "sys_audit_user, sys_audit_time, sys_deleted, " +
            "frame_number, engine_number, claim_number, " +
            "part_code, parts_chinese_name, parts_name_english, " +
            "parts_name_in_russian, order_date, sending_date, " +
            "date_of_arrival, in_the_warehouse, shelf_location, " +
            "scrap_date, date_of_return_to_china, responsible_person, " +
            "warranty_claim_id, warranty_claim_CBU_id, warranty_claim_KD_id) " +
            "values (" +
            "#{id}, #{create_time}, #{update_time}, " +
            "#{creator}, #{process_status}, #{sys_update_user}, " +
            "#{sys_audit_user}, #{sys_audit_time}, #{sys_deleted}, " +
            "#{frame_number}, #{engine_number}, #{claim_number}, " +
            "#{part_code}, #{parts_chinese_name}, #{parts_name_english}, " +
            "#{parts_name_in_russian}, #{order_date}, #{sending_date}, " +
            "#{date_of_arrival}, #{in_the_warehouse}, #{shelf_location}, " +
            "#{scrap_date}, #{date_of_return_to_china}, #{responsible_person}, " +
            "#{warranty_claim_id}, #{warranty_claim_CBU_id}, #{warranty_claim_KD_id})")
    void insertOne(afterSalesFaultPartsPojo pojo);

    //修改一行返件清单
    @DS("newMscLowCodeFormal")
    @Update("update ddm_after_sales_fault_parts " +
            "set " +
            "create_time=#{create_time}, " +
            "update_time=#{update_time}, " +
            "creator=#{creator}, " +
            "process_status=#{process_status}, " +
            "sys_update_user=#{sys_update_user}, "+
            "sys_audit_user=#{sys_audit_user}, " +
            "sys_audit_time=#{sys_audit_time}, " +
            "sys_deleted=#{sys_deleted}, " +
            "frame_number=#{frame_number}, " +
            "engine_number=#{engine_number}, " +
            "claim_number=#{claim_number}, " +
            "part_code=#{part_code}, "+
            "parts_chinese_name=#{parts_chinese_name}," +
            "parts_name_english=#{parts_name_english}, "+
            "parts_name_in_russian=#{parts_name_in_russian}, " +
            "order_date=#{order_date}, " +
            "sending_date=#{sending_date}, " +
            "date_of_arrival=#{date_of_arrival}, " +
            "in_the_warehouse=#{in_the_warehouse}, " +
            "shelf_location=#{shelf_location}," +
            "scrap_date=#{scrap_date}, " +
            "date_of_return_to_china=#{date_of_return_to_china}, "+
            "responsible_person=#{responsible_person} " +
            "where id=#{id}")
    void editOneById(afterSalesFaultPartsPojo pojo);

    //根据三个字段查询返件清单
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_after_sales_fault_parts " +
            "where sys_deleted=0 and ${fieldName1}=#{fieldValue1} and ${fieldName2}=#{fieldValue2} and ${fieldName3}=#{fieldValue3}")
    List<afterSalesFaultPartsPojo> queryThreeFields(String fieldName1, String fieldValue1, String fieldName2, String fieldValue2, String fieldName3, String fieldValue3);

    //动态查询返件清单
    @DS("newMscLowCodeFormal")
    List<afterSalesFaultPartsPojo> queryByDynamicConditions(Map<String, Object> map);

    //查询所有返件清单
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_after_sales_fault_parts where sys_deleted=0")
    List<afterSalesFaultPartsPojo> queryAll();

    //修改返件清单一个字段.依据索赔单关联id
    @DS("newMscLowCodeFormal")
    @Update("update ddm_after_sales_fault_parts set ${firstFieldName}=#{firstFieldValue}, update_time=#{update_time} where warranty_claim_id=#{warranty_claim_id}")
    void editOneField(Integer warranty_claim_id, String firstFieldName, Integer firstFieldValue, LocalDateTime update_time);
    //修改返件清单一个字段.依据索赔单CBU关联id
    @DS("newMscLowCodeFormal")
    @Update("update ddm_after_sales_fault_parts set ${firstFieldName}=#{firstFieldValue}, update_time=#{update_time} where warranty_claim_CBU_id=#{warranty_claim_CBU_id}")
    void editOneFieldCBU(String warranty_claim_CBU_id, String firstFieldName, Integer firstFieldValue, LocalDateTime update_time);
    //修改返件清单一个字段.依据索赔单KD关联id
    @DS("newMscLowCodeFormal")
    @Update("update ddm_after_sales_fault_parts set ${firstFieldName}=#{firstFieldValue}, update_time=#{update_time} where warranty_claim_KD_id=#{warranty_claim_KD_id}")
    void editOneFieldKD(String warranty_claim_KD_id, String firstFieldName, Integer firstFieldValue, LocalDateTime update_time);
}
